@use '../colors.module.scss' as *;

.switch {
  --track-height: 32px;
  --track-width: 52px;
  --border-width: 2px;
  --size-off: 16px;
  --size-on: 24px;
  --icon-size: 16px;
  --gap-on: calc(((var(--track-height) - var(--size-on)) / 2) - var(--border-width));
  --gap-off: calc(((var(--track-height) - var(--size-off)) / 2) - var(--border-width));
}

.switch,
.switch * {
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.switch label {
  cursor: pointer;
}

.switch label input[type=checkbox] {
  opacity: 0;
  width: 0;
  height: 0;

  // CHECKED
  // Track
  &:checked + .lever{
    background-color: var(--md-sys-color-primary);
    border-color:  var(--md-sys-color-primary);
  }
  // Dot
  &:checked + .lever {
    &:before, &:after {
      top: var(--gap-on);
      left: calc(var(--track-width) - var(--size-on) - var(--gap-on) - 2 * var(--border-width));
      width: var(--size-on);
      height: var(--size-on);
    }
    &:after {
      @extend .surface;
    }
  }
}

.switch label .lever {
  content: "";
  display: inline-block;
  position: relative;
  width: var(--track-width);
  height: var(--track-height);
  border-style: solid;
  border-width: 2px;
  border-color: var(--md-sys-color-outline);

  //@extend .surface-variant;
  background-color: var(--md-sys-color-surface-variant);

  border-radius: 15px;
  margin-right: 10px;
  transition: background 0.3s ease;
  vertical-align: middle;
  margin: 0 16px;

  // DOT
  &:before, &:after {
    content: "";
    position: absolute;
    display: inline-block;
    width: var(--size-off);
    height: var(--size-off);
    border-radius: 50%;

    left: var(--gap-off);
    top: var(--gap-off);

    transition: left 0.3s ease, background .3s ease, box-shadow 0.1s ease, transform .1s ease;
  }

  // NOT CHECKED [DOT]
  &:after {
    @extend .outline; 
    height: var(--size-off);
    width: var(--size-off);

    //@extend .surface-variant;
    //box-shadow: 0px 3px 1px -2px rgba(0, 0, 0, 0.2), 0px 2px 2px 0px rgba(0, 0, 0, 0.14), 0px 1px 5px 0px rgba(0, 0, 0, 0.12);
  }
}

input[type=checkbox]:not(:disabled) ~ .lever:active:before,
input[type=checkbox]:not(:disabled).tabbed:focus ~ .lever::before,
input[type=checkbox]:not(:disabled) ~ .lever:hover::before {
    transform: scale(2.4);
}

input[type=checkbox]:checked:not(:disabled) ~ .lever:hover::before {
  background-color: rgba(var(--md-sys-color-primary-numeric), 0.06);
}

// Switch active style
input[type=checkbox]:checked:not(:disabled) ~ .lever:active::before,
input[type=checkbox]:checked:not(:disabled).tabbed:focus ~ .lever::before {
  background-color: rgba(var(--md-sys-color-primary-numeric), 0.18);
}

input[type=checkbox]:not(:disabled) ~ .lever:hover::before {
  background-color: rgba(0, 0, 0, 0.04);
}

input[type=checkbox]:not(:disabled) ~ .lever:active:before,
input[type=checkbox]:not(:disabled).tabbed:focus ~ .lever::before {
  background-color: rgba(0, 0, 0, 0.12);
}

// Disabled Styles
.switch input[type=checkbox][disabled] + .lever {
  cursor: default;
  opacity: 0.5;
}

